package com.yinhe.module.yzx.xlcj;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yinhe.system.domain.YhContract;
import com.yinhe.system.domain.YhSealInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhTrainingResults;
import com.yinhe.system.service.IYhTrainingResultsService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 训练综合成绩评定Controller
 *
 * @author yinhe
 * @date 2022-09-24
 */
@RestController
@RequestMapping("/yzx/xlcj/xlcj")
public class YzxxlcjController extends BaseController
{
    @Autowired
    private IYhTrainingResultsService yhTrainingResultsService;

    /**
     * 查询训练综合成绩评定列表
     */
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhTrainingResults yhTrainingResults)
    {
        startPage();
        List<YhTrainingResults> list = yhTrainingResultsService.selectYhTrainingResultsList(yhTrainingResults);
        return getDataTable(list);
    }

    /**
     * 导出训练综合成绩评定列表
     */
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:export')")
    @Log(title = "训练综合成绩评定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhTrainingResults yhTrainingResults)
    {
        List<YhTrainingResults> list = yhTrainingResultsService.selectYhTrainingResultsList(yhTrainingResults);
        ExcelUtil<YhTrainingResults> util = new ExcelUtil<YhTrainingResults>(YhTrainingResults.class);
        util.exportExcel(response, list, "训练综合成绩评定数据");
    }

    /**
     * 获取训练综合成绩评定详细信息
     */
    /*@PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:query')")*/
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhTrainingResultsService.selectYhTrainingResultsById(id));
    }

    /**
     * 新增训练综合成绩评定
     */
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:add')")
    @Log(title = "训练综合成绩评定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhTrainingResults yhTrainingResults)
    {
        return toAjax(yhTrainingResultsService.insertYhTrainingResults(yhTrainingResults));
    }

    /**
     * 修改训练综合成绩评定
     */
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:edit')")
    @Log(title = "训练综合成绩评定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhTrainingResults yhTrainingResults)
    {
        return toAjax(yhTrainingResultsService.updateYhTrainingResults(yhTrainingResults));
    }

    /**
     * 删除训练综合成绩评定
     */
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:remove')")
    @Log(title = "训练综合成绩评定", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhTrainingResultsService.deleteYhTrainingResultsByIds(ids));
    }




    @Log(title = "训练综合成绩评定", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('yzx:xlcj:xlcj:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<YhTrainingResults> util = new ExcelUtil<YhTrainingResults>(YhTrainingResults.class);
        List<YhTrainingResults> TrainingResultsList = util.importExcel(file.getInputStream());
        String message = yhTrainingResultsService.importTrainingResults(TrainingResultsList, updateSupport);
        return AjaxResult.success(message);
    }
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<YhTrainingResults> util = new ExcelUtil<YhTrainingResults>(YhTrainingResults.class);
        util.importTemplateExcel(response, "信息");
    }

}

